#include <iostream>
#include <string>
#include <cmath>

using namespace std;

bool isPr(int num)
{
    if (num <= 1)
        return false;
    if (num == 2)
        return true;
    if (num % 2 == 0)
        return false;
    for (int i = 3; i <= sqrt(num); i += 2)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}

int main()
{
    string stri[3];
    string w, st, num_s;
    int jl = 0;
    getline(cin, w);
    int i = 0;
    for (int i = 0; i < w.size() + 1; i++)
    {
        if (w[i] == ' ' or i >= w.size())
        {
            stri[jl] = st;
            st = "";
            if (jl == 2)
            {
                break;
            }
            jl++;
        }
        else
        {
            st += w[i];
        }
    }
    if (jl != 2)
    {
        cout << "Wrong input";
        return 0;
    }

    for (int i = 0; i <= 2; i++)
    {
        if (stri[i] == "zero")
        {
            num_s += '0';
        }
        else if (stri[i] == "one")
        {
            num_s += '1';
        }
        else if (stri[i] == "two")
        {
            num_s += '2';
        }
        else if (stri[i] == "three")
        {
            num_s += '3';
        }
        else if (stri[i] == "four")
        {
            num_s += '4';
        }
        else if (stri[i] == "five")
        {
            num_s += '5';
        }
        else if (stri[i] == "six")
        {
            num_s += '6';
        }
        else if (stri[i] == "seven")
        {
            num_s += '7';
        }
        else if (stri[i] == "eight")
        {
            num_s += '8';
        }
        else if (stri[i] == "nine")
        {
            num_s += '9';
        }
        else
        {
            cout << "Wrong input";
            return 0;
        }
    }

    int num = stoi(num_s);

    if (num <= 100 || num >= 999)
    {
        cout << "Wrong input1" << endl;
        return 0;
    }

    int c = 0;
    while (true)
    {
        if (isPr(num - c))
        {
            cout << num - c << endl;
            return 0;
        }
        if (isPr(num + c))
        {
            cout << num + c << endl;
            return 0;
        }
        c++;
    }

    return 0;
}
